home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / tvtoyc01.zip / HELPBASE.H < prev    next >
C/C++ Source or Header  |  1994-01-07  |  5KB  |  204 lines

  1. /* ------------------------------------------------------------------------*/
  2. /*                                                                         */
  3. /*   HELPBASE.H                                                            */
  4. /*                                                                         */
  5. /*   Copyright (c) Borland International 1991                              */
  6. /*   All Rights Reserved.                                                  */
  7. /*                                                                         */
  8. /*   defines the classes TParagraph, TCrossRef, THelpTopic, THelpIndex,    */
  9. /*      THelpFile                                                          */
  10. /*                                                                         */
  11. /* ------------------------------------------------------------------------*/
  12.  
  13. const long magicHeader = 0x46484246L; //"FBHF"
  14.  
  15. #define cHelpColor      "\x37\x3F\x3A\x13\x13\x30\x3E\x1E"
  16. #define cHelpBlackWhite "\x07\x0F\x07\x70\x70\x07\x0F\x70" 
  17. #define cHelpMonochrome "\x07\x0F\x07\x70\x70\x07\x0F\x70"
  18. #define cHelpViewer     "\x06\x07\x08"
  19. #define cHelpWindow     "\x40\x41\x42\x43\x44\x45\x46\x47"
  20.  
  21. // TParagraph
  22.  
  23. class TParagraph
  24. {
  25.   
  26. public:
  27.  
  28.     TParagraph() {}
  29.     TParagraph *next;
  30.     Boolean wrap;
  31.     ushort size;
  32.     char *text;
  33.  
  34. };
  35.  
  36. // TCrossRef
  37.  
  38. class TCrossRef
  39. {
  40.  
  41. public:
  42.  
  43.     TCrossRef() {}
  44.     int ref;
  45.     int offset;
  46.     uchar length;
  47.  
  48. };
  49.  
  50.  
  51. typedef void (*TCrossRefHandler) ( opstream&, int );
  52.  
  53. class THelpTopic: public TObject, public TStreamable
  54. {
  55.  
  56. public:
  57.  
  58.     THelpTopic();
  59.     THelpTopic( StreamableInit ) {};
  60.     virtual ~THelpTopic();
  61.  
  62.     void addCrossRef( TCrossRef ref );
  63.     void addParagraph( TParagraph *p );
  64.     void getCrossRef( int i, TPoint& loc, uchar& length, int& ref );
  65.     char *getLine( int line );
  66.     int getNumCrossRefs();
  67.     int numLines();
  68.     void setCrossRef( int i, TCrossRef& ref );
  69.     void setNumCrossRefs( int i );
  70.     void setWidth( int aWidth );
  71.  
  72.     TParagraph *paragraphs;
  73.  
  74.     int numRefs;
  75.     TCrossRef *crossRefs;
  76.  
  77. private:
  78.  
  79.     char *wrapText( char *text, int size, int& offset, Boolean wrap );
  80.     void readParagraphs( ipstream& s );
  81.     void readCrossRefs( ipstream& s );
  82.     void writeParagraphs( opstream& s );
  83.     void writeCrossRefs( opstream& s );
  84.     void disposeParagraphs();
  85.     const char *streamableName() const
  86.         { return name; }
  87.     int width;
  88.     int lastOffset;
  89.     int lastLine;
  90.     TParagraph *lastParagraph;
  91.  
  92. protected:
  93.  
  94.     virtual void write( opstream& );
  95.     virtual void *read( ipstream& );
  96.  
  97. public:
  98.  
  99.     static const char * const near name;
  100.     static TStreamable *build();
  101.  
  102. };
  103.  
  104. inline ipstream& operator >> ( ipstream& is, THelpTopic& cl )
  105.     { return is >> (TStreamable&)cl; }
  106. inline ipstream& operator >> ( ipstream& is, THelpTopic*& cl )
  107.     { return is >> (void *&)cl; }
  108.  
  109. inline opstream& operator << ( opstream& os, THelpTopic& cl )
  110.     { return os << (TStreamable&)cl; }
  111. inline opstream& operator << ( opstream& os, THelpTopic* cl )
  112.     { return os << (TStreamable *)cl; }
  113.  
  114.  
  115. // THelpIndex 
  116.  
  117. class THelpIndex : public TObject, public TStreamable
  118. {
  119. public:
  120.  
  121.  
  122.     THelpIndex();
  123.     THelpIndex( StreamableInit ) {};
  124.     virtual ~THelpIndex();
  125.  
  126.     long position( int );
  127.     void add( int, long );
  128.  
  129.     ushort size;
  130.     long *index;
  131.  
  132. private:
  133.  
  134.     const char *streamableName() const
  135.         { return name; }
  136.  
  137. protected:
  138.  
  139.     virtual void write( opstream& );
  140.     virtual void *read( ipstream& );
  141.  
  142. public:
  143.  
  144.     static const char * const near name;
  145.     static TStreamable *build();
  146.  
  147. };
  148.  
  149. inline ipstream& operator >> ( ipstream& is, THelpIndex& cl )
  150.     { return is >> (TStreamable&)cl; }
  151. inline ipstream& operator >> ( ipstream& is, THelpIndex*& cl )
  152.     { return is >> (void *&)cl; }
  153.  
  154. inline opstream& operator << ( opstream& os, THelpIndex& cl )
  155.     { return os << (TStreamable&)cl; }
  156. inline opstream& operator << ( opstream& os, THelpIndex* cl )
  157.     { return os << (TStreamable *)cl; }
  158.  
  159.  
  160. // THelpFile
  161.  
  162. class THelpFile : public TObject
  163. {
  164.  
  165. public:
  166.  
  167.     THelpFile( fpstream& s );
  168.     virtual ~THelpFile();
  169.  
  170.     THelpTopic *getTopic( int );
  171.     THelpTopic *invalidTopic();
  172.     void recordPositionInIndex( int );
  173.     void putTopic( THelpTopic* );
  174.  
  175.     fpstream *stream;
  176.     Boolean modified;
  177.  
  178.     THelpIndex *index;
  179.     long indexPos;
  180.  
  181. #ifdef HELPEXTENSIONS
  182.     Boolean helpAlreadyPopped;
  183.  
  184.     enum {maxOldTopics=20};
  185.     static int oldFront;
  186.     static int oldCount;
  187.     static ushort oldTopics[maxOldTopics];
  188. #endif
  189. };
  190.  
  191.  
  192. #ifdef HELPEXTENSIONS
  193. const int previousTopic      = (int)0xEEEE; // A unique help topic number
  194.  
  195. // Doesn't have to be unique unless you use modeless help windows
  196. const ushort cmSwitchToTopic = 63052;
  197. #endif
  198.  
  199.  
  200. extern void notAssigned( opstream& s, int value );
  201.  
  202. extern TCrossRefHandler crossRefHandler;
  203.  
  204.